package shopping;

import java.sql.SQLException;
import java.util.ArrayList;

public class Search {
	private AllGoods allGoods;
	private ArrayList<Goods> searchList = new ArrayList<Goods>();
	
	public ArrayList<Goods> getSearchList() {
		return searchList;
	}


	public void setSearchList(ArrayList<Goods> searchList) {
		this.searchList = searchList;
	}


	public Search() throws SQLException {
		allGoods = new AllGoods();
	}
	
	
	ArrayList<Goods> search(String inputKeyword) {
		String[] keywords = inputKeyword.split(" ");
		
		
		for (Goods goods : allGoods.getGoodsList()) {
			boolean flag = true;
			for (String string : keywords) {
				if (!goods.getName().contains(string)) {
					flag = false;
					break;
				}
			}
			if (flag) {
				searchList.add(goods);			
			}
		}
		
		return searchList;
	}




}
